package com.promis.util;

import com.google.gson.internal.$Gson$Types;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

public class ReflectUtils {

	@SuppressWarnings("unchecked")
	public static <T> Class<T> getClassGenriceType(final Class clazz) {
		return (Class<T>) ((ParameterizedType) clazz.getGenericSuperclass())
				.getActualTypeArguments()[0];
	}

	public static Type getSuperclassTypeParameter(Class<?> subclass) {
		//得到带有泛型的类
		Type superclass = subclass.getGenericSuperclass();
		if (superclass instanceof Class) {
			throw new RuntimeException("Missing type parameter.");
		}
		//取出当前类的泛型
		ParameterizedType parameter = (ParameterizedType) superclass;
		return $Gson$Types.canonicalize(parameter.getActualTypeArguments()[0]);
	}
}
